package com.stm.bi.repository.report;

import com.stm.framework.core.util.ClassUtil;
import com.stm.framework.core.util.StringUtil;
import org.springframework.stereotype.Repository;
import com.stm.framework.repository.BaseRepository;
import com.stm.bi.dto.vo.ReportDimensionVO;
import com.stm.bi.repository.report.mapper.ReportDimensionMapper;
import com.stm.bi.repository.report.dataobject.ReportDimensionDO;
import com.stm.bi.dto.query.ReportDimensionListQry;
import com.stm.bi.dto.query.ReportDimensionPageQry;
import com.stm.framework.model.CustomizePage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;

import java.lang.reflect.Field;
import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.stm.framework.core.tookit.BeanToolkit;
/**
* 报表模型维度-仓储
*
* @author zhouyuanpeng
* @date 2025-05-22
*/
@Repository
public class ReportDimensionRepository extends BaseRepository<ReportDimensionMapper, ReportDimensionDO, ReportDimensionVO> {


    /**
    * 报表模型维度分页查询
    * @param reportDimensionPageQry 报表模型维度查询入参对象
    * @return
    */
   public CustomizePage<ReportDimensionVO> selectPage(ReportDimensionPageQry reportDimensionPageQry){
	LambdaQueryWrapper<ReportDimensionDO> queryWrapper = buildeQueryWrapper(reportDimensionPageQry);
        IPage<ReportDimensionDO> page = new Page(reportDimensionPageQry.getPageNum(),reportDimensionPageQry.getPageSize());
        page = this.baseMapper.selectPage(page, queryWrapper);
        CustomizePage<ReportDimensionVO> customizePage = new CustomizePage(BeanToolkit.instance().copyList(page.getRecords(), ReportDimensionVO.class), page.getSize(), page.getCurrent(), page.getTotal());
        return customizePage;
   }
    /**
    * 报表模型维度列表查询
    * @param reportDimensionListQry 报表模型维度查询入参对象
    * @return
    */
   public List<ReportDimensionVO> selectList(ReportDimensionListQry reportDimensionListQry){
	LambdaQueryWrapper<ReportDimensionDO> queryWrapper = buildeQueryWrapper(reportDimensionListQry);
        List<ReportDimensionDO> records = this.baseMapper.selectList(queryWrapper);
        return BeanToolkit.instance().copyList(records, ReportDimensionVO.class);
   }
   private LambdaQueryWrapper buildeQueryWrapper(ReportDimensionListQry reportDimensionListQry){
	LambdaQueryWrapper<ReportDimensionDO> queryWrapper = Wrappers.<ReportDimensionDO>lambdaQuery()
                .eq(StringUtil.isNotEmpty(reportDimensionListQry.getModelId()),ReportDimensionDO::getModelId,reportDimensionListQry.getModelId())
                .eq(StringUtil.isNotEmpty(reportDimensionListQry.getMode()),ReportDimensionDO::getMode,reportDimensionListQry.getMode())
                .eq(StringUtil.isNotEmpty(reportDimensionListQry.getType()),ReportDimensionDO::getType,reportDimensionListQry.getType())
                .in(StringUtil.isNotEmpty(reportDimensionListQry.getModelIds()),ReportDimensionDO::getModelId,reportDimensionListQry.getModelIds())
                .like(StringUtil.isNotEmpty(reportDimensionListQry.getParam()),ReportDimensionDO::getParams,reportDimensionListQry.getParam())
                .orderByAsc(ReportDimensionDO::getIdx);
        return queryWrapper;
   }

}
